/*
 * @Author: greyqiu greyqiu@163.com
 * @Date: 2023-06-27 16:56:34
 * @LastEditors: greyqiu greyqiu@163.com
 * @LastEditTime: 2023-06-29 17:03:03
 * @FileName: easy_timer_config.h
 * @Description: 
 * 配置easy_timer所使用的时基单元信息，如时基单元的计数方向，计数器频率，获取计数器值的宏，时基初始化
 * 
 * Copyright (c) 2023 by ${git_name}, All Rights Reserved. 
 */

#ifndef _EASY_TIMER_CONFIG_H
#define _EASY_TIMER_CONFIG_H

#include "n32g430.h"

#define COUNTER_DIR_UP          0
#define COUNTER_DIR_DOWN        1

#define GET_TIME_STAMP()        (SysTick->VAL) // 获取当前计数器的值

#define TIMER_DERECTION         COUNTER_DIR_DOWN // ARM-CORTEX内核的systick都是向下计数

#define EASY_TIMER_CLOCK_FREQ   16000000 // 时基频率16Mhz

#define HW_TIMER_BIT            24 // ARM-CORTEX内核的systick定时器为24位
    
#if HW_TIMER_BIT == 16
#define MAX_TICKS 0XFFFF

#elif HW_TIMER_BIT == 24
#define MAX_TICKS 0XFFFFFF

#elif HW_TIMER_BIT == 32
#define MAX_TICKS 0XFFFFFFFF
#endif

__STATIC_INLINE void systick_init(void) {
    SysTick->LOAD = SysTick_LOAD_RELOAD_Msk; // 设置计数器重装值
    SysTick->VAL = 0;
    SysTick->CTRL &= (~SysTick_CTRL_CLKSOURCE_Msk); // 始终选择选择HCLK / 8
    SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk; // 使能Systick
}

#endif	/* _EASY_TIMER_CONFIG_H */

